/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = 'regional';
  
  checkConfig(config);
  @endpoint = getEndpoint('eds-user', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model GetUserByTokenRequest {
  token?: string(name='Token'),
}

model GetUserByTokenResponseBody = {
  requestId?: string(name='RequestId', description='Id of the request'),
  user?: {
    adDomain?: string(name='AdDomain'),
    email?: string(name='Email'),
    id?: long(name='Id'),
    name?: string(name='Name'),
    officeSiteId?: string(name='OfficeSiteId'),
    tenantId?: string(name='TenantId'),
    type?: string(name='Type'),
  }(name='User'),
}

model GetUserByTokenResponse = {
  headers: map[string]string(name='headers'),
  body: GetUserByTokenResponseBody(name='body'),
}

async function getUserByTokenWithOptions(request: GetUserByTokenRequest, runtime: Util.RuntimeOptions): GetUserByTokenResponse {
  Util.validateModel(request);
  var body : map[string]any= {};
  if (!Util.isUnset(request.token)) {
    body['Token'] = request.token;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'GetUserByToken',
    version = '2021-06-22',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function getUserByToken(request: GetUserByTokenRequest): GetUserByTokenResponse {
  var runtime = new Util.RuntimeOptions{};
  return getUserByTokenWithOptions(request, runtime);
}

